

#include "../stdafx.h"
#include "NAsyncWorkResponseQueue.h"
#include "../NSyncObject.h"




NAsyncWorkResponseQueue::NAsyncWorkResponseQueue( void )
{
	m_bOK = false;		
	::InitializeCriticalSection( &m_CS );
	m_bOK = true;
}

NAsyncWorkResponseQueue::~NAsyncWorkResponseQueue(void)
{
	::DeleteCriticalSection( &m_CS );
}


void NAsyncWorkResponseQueue::Put( NAsyncWorkPtr& in_AsyncWorkPtr )
{
	NSyncObject sync( m_CS );
	m_ResponseQueue.push_back( in_AsyncWorkPtr );	
}

pair< bool, NAsyncWorkPtr > NAsyncWorkResponseQueue::Get( void )
{	
	NSyncObject sync( m_CS );
	if( m_ResponseQueue.empty() ) return make_pair( false, NAsyncWorkPtr() );

	NAsyncWorkPtr retAsyncWorkPtr = m_ResponseQueue.front();
	m_ResponseQueue.pop_front();
	return make_pair( true, retAsyncWorkPtr );
}


